﻿// DeviceStateToColorConverter
//
// WPF data binding conversion class for converting DeviceState to (color) string
// 
// FLMScan - Featured by FabLab Munich

using System;
using System.Text;
using System.Windows.Data;
using System.Drawing;

namespace FLMScan.WPF
{    
    [ValueConversion(typeof(object), typeof(string))]
    public class DeviceStateToColorConverter : BaseConverter, IValueConverter
    {
        // convert from DeviceState to Brush
        public object Convert(object value, Type targetType, object parameter,
                          System.Globalization.CultureInfo culture)
        {
            DeviceState state = (DeviceState)value;
            switch (state)
            {
                case DeviceState.eConnected:
                    // return Brushes.Green;
                    return "GreenYellow";
                case DeviceState.eDisconnected:
                    // return Brushes.Red;
                    return "Red";
                case DeviceState.eUnknown:
                    // return Brushes.Gray;
                    return "Gray";
                case DeviceState.eInvalid:
                    // return Brushes.Orange;                
                    return "Orange";
            }

            // return Brushes.Orange;                
            return "Orange";
        }

        // convert from Brush to DeviceState
        public object ConvertBack(object value, Type targetType, object parameter,
                        System.Globalization.CultureInfo culture)
        {
            Brush brush = (Brush)value;

            if(brush == Brushes.Red)
                return DeviceState.eDisconnected;
            else if ( brush == Brushes.Green)
                return DeviceState.eConnected;
            else if ( brush == Brushes.Gray)
                return DeviceState.eUnknown;
            else 
                return DeviceState.eInvalid;            
        }
    }
}
